﻿using System;
using System.Data;
using Team4Mock.Entity;

namespace Team4Mock.UserControl.Government
{
    public partial class ViewAll : System.Web.UI.UserControl
    {
        GovernmentEntity ge=new GovernmentEntity();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(Convert.ToString(Session["role"])))
                {
                    if (Session["role"].ToString().Equals("Admin"))
                    {

                        if (!string.IsNullOrEmpty(Convert.ToString(Request.QueryString["ID"])))
                        {
                            pnView.Visible = false;
                            pnct.Visible = true;
                            int id = int.Parse(Request.QueryString["ID"]);
                            ge.GovOfficeRegionID = id;
                            DataTable dt = new DataTable();
                            dt = ge.GetdataByID(ge);
                            txtName.Text = dt.Rows[0][1].ToString();
                            txtDescription.Text = dt.Rows[0][2].ToString();
                            txtCounty.Text = dt.Rows[0][3].ToString();
                            txtCounty.ReadOnly = true;
                            txtDescription.ReadOnly = true;
                            txtName.ReadOnly = true;
                        }
                        else
                        {
                            pnView.Visible = true;
                            pnct.Visible = false;
                            LoadGV();
                            txtCounty.ReadOnly = false;
                            txtDescription.ReadOnly = false;
                            txtName.ReadOnly = false;
                        }
                    }
                    else
                    {
                        //Quẳng thông báo
                    }
                }
                else
                {
                    Response.Redirect("/FormView/Login.aspx");
                }
            }
        }
        protected void btnCreate_Click(object sender, EventArgs e)
        {
            pnct.Visible = true;
            pnView.Visible = false;
        }
        void LoadGV()
        {
            gvGor.DataSource = ge.Getdata();
            gvGor.DataBind();
        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("/FormView/Government.aspx");
        }
    }
}